package 笔试.thr;

import java.util.*;

public class Main {

    static int n;
    static int[] nums;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n=sc.nextInt();
        nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i]=sc.nextInt();
        }

        Arrays.sort(nums);
        int N = Math.min(n,30);
        int[] p = new int[N];
        for (int i = 0; i < N; i++) {
            p[i]=nums[i];
        }
        int[] dp = new int[p.length];
        dp[0]=p[0];
        for (int i = 1; i < N; i++) {
            dp[i]=dp[i-1]|p[i];
        }
        System.out.println(dp[N-1]);
    }


    static int weishu(int x){
        int len =0;
        while(x!=0){
            x=x/2;
            len++;
        }
        return len;
    }
    static Map<String,Integer> map = new HashMap<>();
    static int back(int ci, int step, int tmp) {
        String key = ci+","+step+","+tmp;
        if(ci==n || step==Math.min(30,n)){
            return 0;
        }

        if(map.containsKey(key)){
            return map.get(key);
        }
        int curMax=tmp;
        for (int i = ci; i < nums.length; i++) {
            if(weishu(tmp)>=weishu(nums[ci]))continue;
            int T = tmp;
            tmp |= nums[i];
            curMax=Math.max(curMax, tmp| back(i+1,step+1,tmp));
            tmp = T;
        }
        map.put(key,curMax);
        return curMax;
    }
}
